<%@ page language="java" import="pandora.bo.DFAJ.*,pandora.dto.*,pandora.bo.login.*,java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<title> New product </title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>


<%
	DBLogin dbl = new DBLogin();

	if(dbl.verifyStore((String)session.getAttribute("session.user"))){
		UpdateCatalog c = new UpdateCatalog();
		//Map<ProductDTO,Integer> map = new HashMap<ProductDTO,Integer>();
		String nif = dbl.obtainStore((String)session.getAttribute("session.user")).getStoreNIF();
		
		NewPriceList sessionPrices = (NewPriceList)session.getAttribute("session.prices");
		
		if(sessionPrices ==null || sessionPrices.getList().size() == 0){
			sessionPrices = new NewPriceList();
		}
	
	String barcode = request.getParameter("barcode");	
	String name = request.getParameter("productName");
	String type = request.getParameter("type");
	String brand = request.getParameter("brand");
	String description = request.getParameter("description");
	
	ProductDTO p = new ProductDTO();
	p.setBarcode(barcode);
	p.setProductName(name);
	p.setProductDetails(description);
	
	BrandDTO b = new BrandDTO();
	b.setBrandName(brand);
	p.setBrand(b);
	
	TypeDTO t = new TypeDTO();
	t.setType(type);
	p.setType(t);
	
	Integer price = Integer.parseInt(request.getParameter("price"));
	
	
	PriceProduct pp = new PriceProduct(p,price);
	
	sessionPrices.add(pp);
	c.updateCatalog(nif,p,price);
	
	session.setAttribute("session.prices", sessionPrices);

	}%>
	
	<jsp:include page="./newProduct.jsp" />

</body>

</html>